﻿using SkyWalking.ProductService.Services;
using SkyWalking.ProductService.Services.Dtos;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace SkyWalking.GateWay.Controllers
{
    /// <summary>
    /// 商城首页控制器
    /// </summary>
    [ApiController]
    [Route("api/app/product")]
    public class ProductController : AbpController,IProductService
    {
        public IProductService productService { set; get; }

        /// <summary>
        /// 创建商品数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("create")]
        public async Task<ProductDto> CreateAsync([FromBody] ProductDto input)
        {
            try
            {
                var dto =  await productService.CreateAsync(input);
                return dto;
            }
            catch (Exception e)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除商品数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete("id")]
        public Task DeleteAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 获取单个商品数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet("id")]
        public Task<ProductDto> GetAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("GetList")]
        public Task<PagedResultDto<ProductDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            return productService.GetListAsync(input);
        }

        /// <summary>
        /// 获取所有商品  
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetProducts")]
        public Task<List<ProductDto>> GetProductsAsync()
        {
            Console.WriteLine("执行查询...GetProductsAsync");
            return productService.GetProductsAsync();
        }

        /// <summary>
        /// 编辑商品数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ProductDto> UpdateAsync(Guid id, ProductDto input)
        {
            return productService.UpdateAsync(id, input);
        }
    }
}
